﻿using System;
using Olympic_email_to_future.Module;
using Olympic_email_to_future.BLLFactory;
using Olympic_email_to_future.IBLL;
using System.Text.RegularExpressions;

namespace FutureMeWeb.FutureMe_Admin
{
    public partial class addUser : System.Web.UI.Page
    {
        public UserInfo userinfo = new UserInfo();
        public IUserBLL user = BusinessFactory.CreateUserBLL();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Submit_Click(object sender, EventArgs e)
        {
           
            userinfo.userMailAddress = login_email.Text;
            userinfo.userPassword =password.Text;
            if (DropDownList_choose.SelectedValue.Equals("1"))
            {
                userinfo.userRole = 1;
            }
            else
            {
                userinfo.userRole = 0;
            }
            String strExp = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
            Regex r = new Regex(strExp);
            Match m = r.Match(login_email.Text);
            if (!m.Success)
            {
                Response.Write("<script>alert('请填写正确邮箱地址');</script>");
            }
            else if (password.Text.Length < 6)
            {
                Response.Write("<script>alert('密码长度要大于6');</script>");
            
            }
            else if (password.Text != password1.Text)
            {
                Response.Write("<script>alert('两次密码不一致');</script>");
            }
            else if (user.add(userinfo))
            {
                Response.Write("<script>alert('添加用户成功');</script>");
            }
            else
            {
                Response.Write("<script>alert('添加失败，请检查输入信息');</script>");
            }
        }
    }
}
